package cn.manjuu.touhou.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import cn.manjuu.touhou.R;
import cn.manjuu.touhou.engine.BaseInfoEngine;
import cn.manjuu.touhou.engine.CardEngine;
import cn.manjuu.touhou.engine.SoundEngine;

public class SplashActivity extends Activity implements OnClickListener {

	private Button btn_help;
	private Button btn_start;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.splash);

		findView();
		registerListener();
		
		init();
	}

	private void init() {
		BaseInfoEngine.getInstance().setContext(getApplicationContext());
		BaseInfoEngine.getInstance().initPlayer();
		
		CardEngine.getInstance().setContext(getApplicationContext());
		
		SoundEngine.getInstance().setContext(getApplicationContext());
	}

	private void findView() {
		btn_start = (Button) findViewById(R.id.btn_start);
		btn_help = (Button) findViewById(R.id.btn_help);

	}

	private void registerListener() {
		// TODO Auto-generated method stub
		btn_start.setOnClickListener(this);
		btn_help.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.btn_start:
			Intent intent = new Intent(this, MainActivity.class);
			startActivity(intent);
			overridePendingTransition(R.anim.alpha_enter, R.anim.alpha_exit);
//			finish();
			break;
		case R.id.btn_help:

			break;
		}
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		SoundEngine.getInstance().restartBGM();
		super.onResume();
	}
	
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		SoundEngine.getInstance().pauseBGM();
		super.onPause();
	}
	
	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		SoundEngine.getInstance().playBGM(R.raw.bgm_marisa);
	}
	
	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		SoundEngine.getInstance().stopBGM();
		super.onStop();
	}
	
}
